package java10;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static List<String> convertStringToList(String line) {
		@SuppressWarnings({ "unchecked", "rawtypes" })
		List<String> List=new ArrayList();
		Scanner sc=new Scanner(line);
		while(sc.hasNext()){
			List.add(sc.next());
		}
		sc.close();
		return List;
	}
    
	public static void remove(List<String> list, String str){
		for (int i = 0; i < list.size(); i++) {
		    if(list.get(i).equals(str)){
			   list.remove(i);
			   i--;
		    }
		}
	}
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNextLine()){
            List<String> list = convertStringToList(sc.nextLine());
            System.out.println(list);
            String word = sc.nextLine();
            remove(list,word);
            System.out.println(list);
        }
        sc.close();
    }
}
